<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDel">
        <span @click="$emit('deleteBtn')">全部删除</span>&nbsp;&nbsp;
        <span @click="isDel = false">完成</span>
      </div>

      <van-icon v-else name="delete" @click="isDel = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHistories"
      :key="index"
      @click="searchItemClick(item, index)"
    >
      <van-icon name="close" v-show="isDel" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isDel: false,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    searchItemClick(item, index) {
      if (this.isDel) {
        this.searchHistories.splice(index, 1)
      } else {
        this.$emit('search', item)
      }
    },
  },
}
</script>

<style scoped lang="less"></style>